import { Injectable, OnModuleInit } from '@nestjs/common';
import { InjectConnection } from '@nestjs/sequelize';
import { Sequelize } from 'sequelize';
import { initSqls } from './utils/tool';
@Injectable()
export class AppService implements OnModuleInit {
    constructor(
        @InjectConnection('lia_web_rtp')
        private seq: Sequelize,
    ) {}

    async onModuleInit() {
        console.log(process.env);

        await initSqls(this.seq);
    }

    async getHello(): Promise<any> {
        return await this.seq.query('select * from cube_device');
    }

    async insertInfo(param) {
        const { name, id } = param;
        try {
            await this.seq.query(`insert into cube_device(table_name, id) values("${name}", ${id} )`);
            return true;
        } catch (_) {
            console.log(_);
            return false;
        }
    }
}
